﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JuXinX.aspx.cs" Inherits="Web.Pages.YongShui.JiChuXX.JuXinX" Theme="Default" %>

<%@ Register Assembly="DevExpress.Web.v15.2, Version=15.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web" TagPrefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../../../JS/AddEditCancel.js"></script>
    <script src="../../../JS/jquery.js"></script>
    <script type="text/javascript">
        //function keyEnter(index) {
        //    var key = event.keyCode;
        //    if (key == 13) {
        //        //debugger;
        //        var controls = new Array();
        //        controls[0] = document.getElementById("ASPxPageControl1_txtJuBH_I");
        //        controls[1] = document.getElementById("ASPxPageControl1_txtJuMingC_I");
        //        controls[2] = document.getElementById("ASPxPageControl1_txtJuDiZ_I");
        //        controls[3] = document.getElementById("ASPxPageControl1_txtYouBian_I");
        //        controls[4] = document.getElementById("ASPxPageControl1_txtLianXiDH_I");
        //        controls[5] = document.getElementById("ASPxPageControl1_txtLianXiBM_I");
        //        controls[6] = document.getElementById("ASPxPageControl1_txtLianXiR_I");
        //        controls[7] = document.getElementById("ASPxPageControl1_ddlYeWuY_I");
        //        controls[8] = document.getElementById("ASPxPageControl1_txtBeiZhu_I");
        //        index = index + 1;
        //        if (index == controls.length) {
        //            index = 0;
        //        }
        //        if (controls[index].disabled == false) {
        //            controls[index].focus();
        //        }
        //    }
        //}
    </script>
    <script type="text/javascript">
        function ClearInfo() {
            hdCollection.Set("ID", -1);
            txtJuBH.SetText("");
            txtJuMingC.SetText("");
            txtJuDiZ.SetText("");
            txtYouBian.SetText("");
            txtLianXiDH.SetText("");
            txtLianXiBM.SetText("");
            txtLianXiR.SetText("");
            ddlYeWuY.SetText("");
            txtBeiZhu.SetText("");
        }

        function SetEnabled(enabled) {
            txtJuBH.SetEnabled(enabled);
            txtJuMingC.SetEnabled(enabled);
            txtJuDiZ.SetEnabled(enabled);
            txtYouBian.SetEnabled(enabled);
            txtLianXiDH.SetEnabled(enabled);
            txtLianXiBM.SetEnabled(enabled);
            txtLianXiR.SetEnabled(enabled);
            ddlYeWuY.SetEnabled(enabled);
            txtBeiZhu.SetEnabled(enabled);
        }

        function display(op) {
            if (gvList.GetFocusedRowIndex()==-1)
            {
                return;
            }
            hdCollection.Set("op", op);
            if (hdCollection.Get("op") == "add" || hdCollection.Get("op") == "edit") {
                btnAdd.SetVisible(false);
                btnEdit.SetVisible(false);
                btnDel.SetVisible(false);
                btnSave.SetVisible(true);
                btnCancel.SetVisible(true);
                SetEnabled(true);                
                listCover(true, "divList");
            }
            else if (hdCollection.Get("op") == "init") {
                btnAdd.SetVisible(true);
                btnEdit.SetVisible(true);
                btnDel.SetVisible(true);
                btnSave.SetVisible(false);
                btnCancel.SetVisible(false);
                SetEnabled(false);
                listCover(false, "divList");
            }
            else if (hdCollection.Get("op") == "ym") {
                if (conNianYu.GetText() == "历史年月") {
                    conLiShiNY.SetVisible(true);
                    btnAdd.SetVisible(false);
                    btnEdit.SetVisible(false);
                    btnDel.SetVisible(false);
                    ClearInfo();
                }
                else {
                    conLiShiNY.SetVisible(false);
                    btnAdd.SetVisible(true);
                    btnEdit.SetVisible(true);
                    btnDel.SetVisible(true)
                }
            }
            if (op == "add") {
                ClearInfo();
                txtJuBH.Focus();
            }
            else if (op == "edit") {
                txtJuBH.SetEnabled(false);
                txtJuMingC.Focus();
            }
            else if (op == "init") {
                txtJuBH.SetEnabled(false);
                hdCollection.Set("ID", gvList.GetRowKey(gvList.GetFocusedRowIndex()));
                ASPxCallback1.PerformCallback("setinfo");
            }
        }

        function YMSelecedChange(s) {
            display("ym");            
            bind();
        }

        function lishiny() {
            if (conLiShiNY.GetText().length != 6) {
                alert("请输入正确的历史年月。");
                return;
            }
            if (conLiShiNY.GetText() >= hdCollection.Get("YM")) {
                alert("历史年月应小于当前水量年月。");
                return;
            }
            bind();
        }

        function search()
        {
            if (conJuBH.GetText()=="")
            {
                return;
            }
            ASPxCallback1.PerformCallback("search");
        }

        function bind() {
            gvList.PerformCallback();
        }

        function rowClick() {
            var id = -1;            
            if (gvList.GetFocusedRowIndex() != -1) {
                id = gvList.GetRowKey(gvList.GetFocusedRowIndex());
                hdCollection.Set("ID", id);
                loadpanel1.Show();
                ASPxCallback1.PerformCallback("setinfo");
                
            }
            else {
                ClearInfo();
                hdCollection.Set("ID", id);                        
            }
            gvList2.PerformCallback(id);
        }
        function endcallback() {
            rowClick();
            //var id = -1;
            //if (gvList.GetFocusedRowIndex() != -1) {
            //    id=gvList.GetRowKey(gvList.GetFocusedRowIndex());
            //    hdCollection.Set("ID",id );
            //    ASPxCallback1.PerformCallback("setinfo");                
            //}
            //else {
            //    ClearInfo();
            //    hdCollection.Set("ID", id);
            //}
            //gvList2.PerformCallback(id);
        }
        
      
        function gvList2EndCallback() {
            lblCountTip.SetText("【" + txtJuMingC.GetText() + "】共" + gvList2.GetVisibleRowsOnPage() + "家公司");
        }

        function save() {
            if (txtJuBH.GetText() == "") {
                alert("你没有输入局的编号，请修改。");
                return;
            }
            if (!isAllNum(txtJuBH.GetText()))
            {
                alert("请输入正确的局编号。");
                return;
            }
            if (txtJuMingC.GetText() == "") {
                alert("你没有输入局的名称，请修改。");
                return;
            }
            if (ddlYeWuY.GetText() == "") {
                alert("请选择业务员！");
                return;
            }
            ASPxCallback1.PerformCallback("save");
        }

        function del() {
            if (gvList.GetFocusedRowIndex() == -1) {
                alert("未选择局。");
                return;
            }
            ASPxCallback1.PerformCallback("deleteValidate");
        }

        function ASPxCallback1Complete(rs) {
            var arr = rs.split('|');
            var type = arr[0];
            var state = arr[1];
            loadpanel1.Hide();
            if (state != "0") {
                alert(arr[2]);
            }
            else {
                if (type == "save") {                    
                    alert(arr[2]);
                    display("init");
                    if (conNianYu.GetText() == "下一月" || conNianYu.GetText() == "当前月") {
                        bind();
                    }
                }
                else if (type == "deleteValidate") {
                    if (confirm("当前局没有使用,你确认要删除吗?")) {
                        ASPxCallback1.PerformCallback("delete");
                    }
                }
                else if (type == "delete") {
                    alert(arr[2]);
                    ClearInfo();
                    gvList.PerformCallback();
                }
                else if (type == "search") {
                    gvList.SetFocusedRowIndex(arr[2]);
                    gvList.MakeRowVisible(arr[2]);                    
                }
                else if (type=="setinfo")
                {
                    txtJuBH.SetText(arr[2]);
                    txtJuMingC.SetText(arr[3]);
                    txtJuDiZ.SetText(arr[4]);
                    txtYouBian.SetText(arr[5]);
                    txtLianXiDH.SetText(arr[6]);
                    txtLianXiBM.SetText(arr[7]);
                    txtLianXiR.SetText(arr[8]);
                    ddlYeWuY.SetValue(arr[9]);
                    txtBeiZhu.SetText(arr[10]);
                }
            }
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <div class="tabletitle1" align="center">
            局信息
        </div>
        <div style="display: none;">
            <dx:ASPxHiddenField ID="hdCollection" ClientInstanceName="hdCollection" runat="server"></dx:ASPxHiddenField>
            <dx:ASPxButton ID="btnActPerform" ClientInstanceName="btnActPerform" runat="server" Text="ASPxButton" OnClick="btnActPerform_Click"></dx:ASPxButton>
            <dx:ASPxCallback ID="ASPxCallback1" ClientInstanceName="ASPxCallback1" runat="server" OnCallback="ASPxCallback1_Callback" ClientSideEvents-CallbackComplete="function(s,e){ASPxCallback1Complete(e.result);}"></dx:ASPxCallback>
        </div>
        <div style="height: 3px"></div>
        <div style="width: 100%">
            <div style="float: left; width: 38%;" id="divList">
                <table width="100%" border="0">
                    <tr>
                        <td colspan="3">
                            <table style="width: 100%">
                                <tr>
                                    <td style="white-space: nowrap; width: 1%">站点：</td>
                                    <td>
                                        <dx:ASPxComboBox runat="server" ID="conZhanDian" ClientInstanceName="conZhanDian" Width="90px" ClientSideEvents-SelectedIndexChanged="function(s,e){bind();}">
                                        </dx:ASPxComboBox>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="white-space: nowrap; width: 1%;">局编号/局名称：</td>
                        <td style="width: 40%">
                            <dx:ASPxTextBox ID="conJuBH" ClientInstanceName="conJuBH" runat="server" Width="100%">
                                <ClientSideEvents KeyPress="function(s,e){var key = event.keyCode;
                                        if( key==13){search();}}" />
                            </dx:ASPxTextBox>
                        </td>
                        <td>
                            <dx:ASPxButton ID="btnSearch" ClientInstanceName="btnSearch" runat="server" Text="查询" AutoPostBack="false" ClientSideEvents-Click="function(s,e){search();}"></dx:ASPxButton>
                        </td>
                    </tr>
                </table>
                <asp:UpdatePanel runat="server" ID="updatePanel1">
                    <ContentTemplate>
                        <dx:ASPxGridView ID="gvList" ClientInstanceName="gvList" runat="server" AutoGenerateColumns="False" KeyFieldName="ID" Theme="Aqua1"
                            Width="100%" OnCustomCallback="gvList_CustomCallback" EnableCallBacks="true">
                            <Columns>
                                <dx:GridViewDataTextColumn FieldName="S_BIANHAO" Caption="编号" Width="20%">
                                </dx:GridViewDataTextColumn>
                                <dx:GridViewDataTextColumn FieldName="S_MINGCHENG" Caption="局名称" Width="80%">
                                </dx:GridViewDataTextColumn>
                            </Columns>
                            <SettingsBehavior AllowFocusedRow="True"  ColumnResizeMode="Control" ProcessFocusedRowChangedOnServer="false" />
                            <ClientSideEvents FocusedRowChanged="function(s,e){rowClick();}" EndCallback="function(s,e){endcallback();}" Init="function(s,e){AdjustSize(100,gvList);}"/>
                        </dx:ASPxGridView>
                    </ContentTemplate>
                </asp:UpdatePanel>                            
                <dx:ASPxLoadingPanel ID="ASPxLoadingPanel1" ClientInstanceName="loadpanel1" runat="server" ContainerElementID="gvList" Modal="true" Theme="Metropolis" ShowImage="true" Text="" ></dx:ASPxLoadingPanel>
            </div>
            <div style="float: left; width: 1%;">&nbsp;</div>
            <div style="float: left; width: 60%; overflow: auto;">
                <dx:ASPxPageControl ID="ASPxPageControl1" runat="server" ActiveTabIndex="0" Width="98%" Height="535px">
                    <TabPages>
                        <dx:TabPage Text="局信息">
                            <ContentCollection>
                                <dx:ContentControl runat="server" SupportsDisabledAttribute="True">
                                    <table border="0" style="width: 100%" id="GridViewContentTable" runat="server">
                                        <tr>
                                            <td>
                                                <table border="0" style="width: 100%">
                                                    <tr>
                                                        <td style="width: 20%;"></td>
                                                        <td style="width: 30%">
                                                            <dx:ASPxComboBox runat="server" ID="conNianYu" ClientInstanceName="conNianYu" Width="100%" ClientSideEvents-SelectedIndexChanged="function(s,e){YMSelecedChange(s);}">
                                                                <Items>
                                                                    <dx:ListEditItem Text="当前月" Value="0" Selected="true" />
                                                                    <dx:ListEditItem Text="下一月" Value="1" />
                                                                    <dx:ListEditItem Text="历史年月" Value="3" />
                                                                </Items>
                                                            </dx:ASPxComboBox>

                                                        </td>
                                                        <td style="width: 50%">
                                                            <dx:ASPxTextBox ID="conLiShiNY" ClientInstanceName="conLiShiNY" runat="server" Width="80px" MaxLength="6" ClientSideEvents-KeyPress="function(s,e){if(event.keyCode==13){lishiny();}}">
                                                            </dx:ASPxTextBox>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                        <table style="width: 100%">
                                                            <tr>
                                                                <td align="right" style="width: 20%; white-space: nowrap;">局编号：
                                                                </td>
                                                                <td style="width: 30%">
                                                                    <dx:ASPxTextBox ID="txtJuBH" ClientInstanceName="txtJuBH" ClientEnabled="false" runat="server" Width="100%" MaxLength="5">

                                                                        <ClientSideEvents  KeyPress="function(s,e){OnKeyNext(txtJuMingC);}" />
                                                                    </dx:ASPxTextBox>
                                                                </td>
                                                                <td style="width: 20%"></td>
                                                                <td style="width: 30%"></td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">局名称：
                                                                </td>
                                                                <td colspan="3">
                                                                    <dx:ASPxTextBox ID="txtJuMingC" ClientInstanceName="txtJuMingC" ClientEnabled="false" runat="server" Text="111" Width="100%" MaxLength="50">

                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtJuDiZ);}" />
                                                                    </dx:ASPxTextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">局地址：
                                                                </td>
                                                                <td colspan="3">
                                                                    <dx:ASPxTextBox ID="txtJuDiZ" ClientInstanceName="txtJuDiZ" ClientEnabled="false" runat="server" Width="100%" MaxLength="100">
                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtYouBian);}" />
                                                                    </dx:ASPxTextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">邮编：
                                                                </td>
                                                                <td>
                                                                    <dx:ASPxTextBox ID="txtYouBian" ClientInstanceName="txtYouBian" ClientEnabled="false" runat="server" Width="100%" MaxLength="10">
                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtLianXiDH);}" />
                                                                    </dx:ASPxTextBox>
                                                                </td>
                                                                <td align="right" style="white-space: nowrap;">联系电话：
                                                                </td>
                                                                <td>
                                                                    <dx:ASPxTextBox ID="txtLianXiDH" ClientInstanceName="txtLianXiDH" ClientEnabled="false" runat="server" Width="100%" MaxLength="50">
                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtLianXiBM);}" />
                                                                    </dx:ASPxTextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right" style="white-space: nowrap;">联系部门：
                                                                </td>
                                                                <td>
                                                                    <dx:ASPxTextBox ID="txtLianXiBM" ClientInstanceName="txtLianXiBM" ClientEnabled="false" runat="server" Width="100%" MaxLength="30">
                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtLianXiR);}" />
                                                                    </dx:ASPxTextBox>
                                                                </td>
                                                                <td align="right">联系人：
                                                                </td>
                                                                <td>
                                                                    <dx:ASPxTextBox ID="txtLianXiR" ClientInstanceName="txtLianXiR" ClientEnabled="false" runat="server" Width="100%" MaxLength="30">
                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(ddlYeWuY);}" />
                                                                    </dx:ASPxTextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">业务员：
                                                                </td>
                                                                <td>
                                                                    <dx:ASPxComboBox runat="server" ID="ddlYeWuY" ClientInstanceName="ddlYeWuY" ClientEnabled="false" Width="100%">
                                                                        <Items>
                                                                        </Items>
                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(txtBeiZhu);}" />
                                                                    </dx:ASPxComboBox>
                                                                </td>
                                                                <td></td>
                                                                <td></td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right" valign="top">备注：
                                                                </td>
                                                                <td colspan="3">
                                                                    <dx:ASPxMemo ID="txtBeiZhu" ClientInstanceName="txtBeiZhu" ClientEnabled="false" runat="server" Width="400px" MaxLength="133">
                                                                        <ClientSideEvents KeyPress="function(s,e){OnKeyNext(btnSave);}" />
                                                                    </dx:ASPxMemo>
                                                                </td>
                                                            </tr>
                                                        </table>
                                            </td>
                                        </tr>
                                    </table>
                                    <div align="right">
                                        <hr />
                                        <dx:ASPxButton ID="btnAdd" ClientInstanceName="btnAdd" runat="server" Text="添加" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('add');}">
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnEdit" ClientInstanceName="btnEdit" runat="server" Text="修改" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('edit');}">
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnDel" ClientInstanceName="btnDel" runat="server" Text="删除" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){del();}">
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnSave" ClientInstanceName="btnSave" runat="server" Text="保存" ClientVisible="false" AutoPostBack="false" UseSubmitBehavior="false">
                                            <ClientSideEvents Click="function(s, e){save();}" />
                                        </dx:ASPxButton>
                                        <dx:ASPxButton ID="btnCancel" ClientInstanceName="btnCancel" runat="server" Text="放弃" ClientVisible="false" AutoPostBack="false" UseSubmitBehavior="false" ClientSideEvents-Click="function(s,e){display('init');}">
                                        </dx:ASPxButton>
                                    </div>
                                </dx:ContentControl>
                            </ContentCollection>
                        </dx:TabPage>
                        <dx:TabPage Text="下属公司信息">
                            <ContentCollection>
                                <dx:ContentControl>
                                    <dx:ASPxLabel ID="lblCountTip" ClientInstanceName="lblCountTip" runat="server" Text="【上海纺织控股(集团)公司】共18家公司"></dx:ASPxLabel>                                    
                                    <dx:ASPxGridView ID="gvGongSi" ClientInstanceName="gvList2" runat="server" AutoGenerateColumns="False" KeyFieldName="ID" Settings-HorizontalScrollBarMode="Auto" Theme="Aqua1" Width="100%" OnCustomCallback="gvGongSi_CustomCallback">
                                        <Columns>
                                            <dx:GridViewDataTextColumn FieldName="S_BIANHAO" Caption="编号" Width="10%">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn FieldName="S_MINGCHENG" Caption="公司名称" Width="25%">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn FieldName="S_DIZHI" Caption="公司地址" Width="20%">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn FieldName="S_YOUBIAN" Caption="邮编" Width="10%">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn FieldName="S_LIANXIBM" Caption="联系部门" Width="12.5%">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn FieldName="S_LIANXIR" Caption="联系人" Width="10%">
                                            </dx:GridViewDataTextColumn>
                                            <dx:GridViewDataTextColumn FieldName="S_LIANXIDH" Caption="联系电话" Width="12.5%">
                                            </dx:GridViewDataTextColumn>
                                        </Columns>
                                        <Settings VerticalScrollableHeight="440" VerticalScrollBarMode="Auto" />
                                        <ClientSideEvents EndCallback="function(s,e){gvList2EndCallback();}"  Init="function(s,e){AdjustSize(150,gvList);}"/>
                                    </dx:ASPxGridView>
                                </dx:ContentControl>
                            </ContentCollection>
                        </dx:TabPage>
                    </TabPages>
                </dx:ASPxPageControl>
            </div>
        </div>      

    </form>
</body>
</html>


